//
//  JYPublicCell.m
//  JYFarm
//
//  Created by 花花 on 2017/10/20.
//  Copyright © 2017年 花花. All rights reserved.
//

#import "JYPublicCell.h"
#import "JYFontColorTool.h"
@implementation JYPublicCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.minBtn.layer.borderWidth =1.0;
    self.minBtn.layer.borderColor = [UIColor colorWithHexString:@"62C6B2"].CGColor;
    self.minBtn.layer.cornerRadius = self.minBtn.frame.size.width * 0.5;
    
    
    
    self.maxBtn.layer.borderWidth =1.0;
    self.maxBtn.layer.borderColor = [UIColor colorWithHexString:@"62C6B2"].CGColor;
    self.maxBtn.layer.cornerRadius = self.maxBtn.frame.size.width * 0.5;
    self.maxBtn.layer.masksToBounds = YES;
    
    
    self.bordView.layer.borderWidth = 1;
    self.bordView.layer.borderColor = [UIColor colorWithHexString:@"F2F2F2"].CGColor;
    
}


- (IBAction)starsBtnOnClick:(UIButton *)sender {
    
    
    sender.selected = !sender.selected;
    if (self.selectStarsBtnClick) {
        self.selectStarsBtnClick(sender.selected);
    }
    
    
}
- (void)insertSubview:(UIView *)view atIndex:(NSInteger)index {
    [super insertSubview:view atIndex:index];
    
    if ([view isKindOfClass:NSClassFromString(@"UITableViewCellDeleteConfirmationView")]) {
        view.top = 10;
        view.height = self.height - 10;
        
        for (UIButton *btn in view.subviews) {
            
            if ([btn isKindOfClass:[UIButton class]]) {
                
                [btn setBackgroundColor:kf2Color];
                
                [btn setTitle:nil forState:UIControlStateNormal];
                
                [btn setImage:[UIImage imageNamed:@"list_deleting"] forState:UIControlStateNormal];
                
                [btn setTintColor:[UIColor whiteColor]];
            }
        }
    }
}



- (void)setModel:(CategoryModel *)model{

    _model = model;
    self.nameLabel.text =  [NSString stringWithFormat:@"大白菜大白菜大白菜大白菜大白菜大白菜大白菜大白菜大白菜大白菜%zd",arc4random_uniform(20)];
    
    self.imgView.image = [UIImage imageNamed:@"home_icon_meat"];
    
    NSString *total = [NSString stringWithFormat:@"￥%zd/个",arc4random_uniform(150)];
    NSArray *subArray = @[ [NSString stringWithFormat:@"/个"]];
    self.priceLabel.attributedText = [JYFontColorTool jy_changeCorlor:k9Color TotalString:total SubStringArray:subArray];
    
//    self.priceLabel.text = [NSString stringWithFormat:@"%zd元",arc4random_uniform(100)];
    
    
//    if (model.selected) {
//        self.starsBtn.selected = YES;
//    }else{
//        self.starsBtn.selected = NO;
//    }


}

- (void)setListModel:(JYListModel *)listModel{


    _listModel = listModel;
    self.nameLabel.text = listModel.goodsName;
    
    
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[listModel.goodsprice doubleValue]];
    
    self.unitLabel.text  = @"/斤";
    self.oldPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[listModel.originalprice doubleValue]];
    
    [self.imgView sd_setImageWithURL:[NSURL URLWithString:listModel.goodsPictureUrl] placeholderImage:defaultFarmImage];
    

}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setHomeModel:(BaseModel *)homeModel{

    _homeModel = homeModel;
    
    self.nameLabel.text = homeModel.name;
//    self.priceLabel.text = homeModel.originalPrice;
//
    self.priceLabel.text = [NSString stringWithFormat:@"￥%.2f",[homeModel.originalPrice doubleValue]];
    
    self.unitLabel.text  = @"/斤";
    self.oldPriceLabel.text = [NSString stringWithFormat:@"￥%.2f",[homeModel.originalPrice doubleValue]];
    
    
    self.count.text = [NSString stringWithFormat:@"%zd",homeModel.goodsAmount];

    [self.imgView sd_setImageWithURL:[NSURL URLWithString:homeModel.image] placeholderImage:defaultFarmImage];
    
    if (homeModel.collect == 0) {
        self.starsBtn.selected = YES;
    }else{
        self.starsBtn.selected = NO;
    }
    
}
- (IBAction)addOnClick {
    
    
    NSInteger count = self.count.text.integerValue;
    if (self.ShopCountEditBlock) {
        self.ShopCountEditBlock(++count);
    }
    
    
}
- (IBAction)minOnClick {
    
    
    NSInteger count = self.count.text.integerValue;
    if (self.ShopCountEditBlock) {
        self.ShopCountEditBlock(--count);
    }
}


@end
